package org.roger.almeida.server.services;

import java.util.Date;

import javax.jdo.PersistenceManagerFactory;

import org.roger.almeida.client.services.ProjectService;
import org.roger.almeida.server.factories.EntityManagerRepository;
import org.roger.almeida.server.model.Project;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class ProjectServiceImpl extends RemoteServiceServlet implements ProjectService{

	@Override
	public Long saveProject(String name, Date starDate, Date endDate, String description) {
		
		PersistenceManagerFactory persistenceManagerFactory = EntityManagerRepository.get();
		
		Project project = new Project();
		project.setName(name);
		project.setDescription(description);
		project.setStartDate(starDate);
		project.setEndDate(endDate);
		project.setCreationDate(new Date());
		persistenceManagerFactory.getPersistenceManager().makePersistent(project);
		
		return project.getId();
	}

}
